<?php
class Loan extends AppModel {
	var $name = 'Loan';
	//The Associations below have been created with all possible keys, those that are not needed can be removed

	var $belongsTo = array(
		'Person' => array(
			'className' => 'Person',
			'foreignKey' => 'person_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'User' => array(
			'className' => 'User',
			'foreignKey' => 'user_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

	var $hasAndBelongsToMany = array(
		'Copy' => array(
			'className' => 'Copy',
			'joinTable' => 'copies_loans',
			'foreignKey' => 'loan_id',
			'associationForeignKey' => 'copy_id',
			'unique' => true,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'finderQuery' => '',
			'deleteQuery' => '',
			'insertQuery' => ''
		)
	);

	var $validate = array(
    	'person_id' => array(
        	'rule' => array('minLength', 36),  
        	'message' => 'Invalid Person'
    )
);

	function findByCopyId($id) {
		
		return $this->Copy->findById($id);
	}
	
}
?>